package com.keyleaf.up.document.controller;


import com.keyleaf.up.document.model.dto.FileMergeAndDownloadDTO;
import com.keyleaf.up.document.model.dto.FileMergeDTO;
import com.keyleaf.up.document.service.IDocumentService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.core.io.InputStreamResource;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author keyleaf
 * @since 2025/5/30
 **/
@RequestMapping("/document")
@RestController
@Slf4j
@RequiredArgsConstructor
public class DocumentController {

    private final IDocumentService documentService;

    /**
     * 合并
     *
     * @param fileMergeDTO 参数
     * @return 合并后的文件路径
     */
    @PutMapping("/merge")
    public String merge(@RequestBody FileMergeDTO fileMergeDTO) {
        return documentService.merge(fileMergeDTO);
    }

    /**
     * 合并并下载
     *
     * @param fileMergeAndDownloadDTO 参数
     * @return 合并后的文件流
     */
    @PutMapping("/mergeAndDownload")
    public ResponseEntity<InputStreamResource> mergeAndDownload(@RequestBody FileMergeAndDownloadDTO fileMergeAndDownloadDTO) {
        return documentService.mergeAndDownload(fileMergeAndDownloadDTO);
    }
}
